<template>
  <!-- 通知通告查看页面 -->
  <div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="90"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      height="auto"
      columnsRef="notification_view_index_01"
    >
    </FilterTable>

    <!-- 详情窗口 -->
    <Drawer
      :visible.sync="visibleDrawer"
      title="通知通告查看"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>

  </div>
</template>

<script>
import { pageNotificationFeedback } from '@/api/cms-api/notificationDLR/view/index';
import { dictionary } from '@/utils/dictMixin';
import infoModal from './info';

export default {
  name:'notificationView',
   mixins: [dictionary],
   components: {
    infoModal
   },
   data(){
     return {
       topFilterInit: this.topFilterInitFun(),
       columns: this.creatHeader(),
       fetchApi:pageNotificationFeedback,
       fetchParams: {status:15631002,
                     xhrAbort: false  //触发自动搜索功能,turen为不触发,false为自动

       },
       visibleDrawer:false,
       initData:{}
     }
   },
   methods:{
     topFilterInitFun() {
      return [
        { type: 'SELECT', label: '类别', fieldName: 'notificationType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1561') },
        { type: 'INPUT', label: '主题', fieldName: 'notificationTitle', placeholder: '请输入', initialValue: '' },
        { type: 'RANGE_DATE', label: '发布时间', fieldName: 'publisDate', valueFormat: 'yyyy-MM-dd', placeholder: '请选择' },
        { type: 'SELECT', label: '紧急程度', fieldName: 'urgency', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1562') },
        { type: 'SELECT', label: '阅读状态', fieldName: 'status', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1563') }
      ]
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row,'show')}>
                  详情
                </el-button>
              </div>
            );
          }
        },
        {
          title: '类别',
          dataIndex: 'notificationType',
          sorter: true,
          filterItems: this.createDictList('1561'),
          render: props => {
            return <span>{this.createDictText(props.row.notificationType, '1561')}</span>;
          }
        },
        { title: '主题', dataIndex: 'notificationTitle', sorter: true },
        { title: '编号', dataIndex: 'notificationNo', sorter: true },
        {
          title: '紧急程度',
          dataIndex: 'urgency',
          sorter: true,
          filterItems: this.createDictList('1562'),
          render: props => {


            if (props.row.urgency == 15621001){
             return <span style='color:red'>{this.createDictText(props.row.urgency, '1562')}<i class='el-icon-s-flag' style='color:red;  margin-left:5px;'></i></span>
            }else if(props.row.urgency == 15621002){
            return <span style='color:orange'>{this.createDictText(props.row.urgency, '1562')}<i class='el-icon-s-flag' style='color:orange; margin-left:5px;' ></i></span>
            }else if(props.row.urgency == 15621003){
               return <span style='color:black'>{this.createDictText(props.row.urgency, '1562')}</span>
            }else if(props.row.urgency == 15621004){
               return <span style='color:black'>{this.createDictText(props.row.urgency, '1562')}</span>
            }

          }
        },
        { title: '发起部门', dataIndex: 'publishOrgName', sorter: true },
        { title: '发布人', dataIndex: 'publishPersonName', sorter: true },
        {
          title: '阅读状态',
          dataIndex: 'status',
          sorter: true,
          filterItems: this.createDictList('1563'),
          render: props => {
            return <span>{this.createDictText(props.row.status, '1563')}</span>;
          }
        },
        { title: '有效期至', dataIndex: 'endTime', sorter: true ,dateFormat:'yyyy-MM-dd'},
        { title: '发布时间', dataIndex: 'publishDate',dateFormat:'yyyy-MM-dd HH:mm',sorter: true }
      ]
    },
    //搜索获取数据
    changeHandle(val) {
       if(!val.status){
        // val.statuss = val.statusList.join(',');
		  val.statuss = "15631001,15631002";
	  }else{
		  val.statuss = "";
	  }
      this.fetchParams = Object.assign({},val);
      this.fetchParams.publisStartDate = this.fetchParams.publisDate[0];
      this.fetchParams.publisEndDate = this.fetchParams.publisDate[1];
      console.log('搜索框数据：',this.fetchParams);
    },
    //展开收起时触发
    collapseHandle() {},
    editHandle(row,type){
      console.log("row:",row);
      this.initData =  {
        type: type,   // add-edit-show
        notificationId: row.notificationId,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    //关闭详情 rData 是页面关闭回调回来的数据
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
   }
};
</script>

<style lang="less" scoped>
// .el-icon-s-flag{ color: red; margin-left:5px;}
// .el-icon-s-flag{ color: rgb(255, 213, 0); margin-left:5px;}
</style>
